package com.pony.iphone.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Random;

/**
 * @author pony
 * @version 1.0
 * @description: 接收lua传来的问题以及问题的所有答案【数组】
 * @create 2025/8/19 22:38
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "问题及答案传输对象")
public class QuestionAnswerDto {
    // 问题
    @Schema(description = "问题内容")
    @NotBlank(message = "问题内容不能为空")
    private String question;
    // 问题的所有答案
    @Schema(description = "问题的所有答案")
    @NotBlank(message = "问题的所有答案")
    private List<String> answerList;
    // 题库名称，默认是 iphone 题库
    @Schema(description = "题库名称")
    @NotBlank(message = "默认是 iphone 题库    ")
    private String libraryName;

    /**
     * 获取一个随机答案
     * @return
     */
    public String getRandomAnswer(){
        if (this.answerList == null || this.answerList.isEmpty()) {
            return null;
        }
        return this.answerList.get(new Random().nextInt(this.answerList.size()));
    }
}
